<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
		<link rel="stylesheet" type="text/css" href="/css/common.css" />
		<link rel="stylesheet" type="text/css" href="/js/flatpickr.min.css" />
		<link rel="stylesheet" type="text/css" href="/bootstrap-3.3.7/css/bootstrap.min.css" />
		<link rel="stylesheet" type="text/css" href="/dialog/css/dialog.css" />
		<link rel="stylesheet" type="text/css" href="/css/font-awesome.css" />

        <script src="/js/jquery-1.9.1.min.js" type="text/javascript" charset="utf-8"></script>
        <script src="/js/google-maps.js" type="text/javascript" charset="utf-8"></script>
        <script src="/js/jquery.form.js"></script>
        <script src="/dialog/js/dialog.js"></script>
        <script src="/js/jquery.validate.min.js" type="text/javascript" charset="utf-8"></script>
        <script src="/js/messages_zh.min.js" type="text/javascript" charset="utf-8"></script>
        <script src="/js/common.js" type="text/javascript" charset="utf-8"></script>
        <script src="/js/flatpickr.js"></script>
		<script type="text/javascript">
			function delete1(id) {
				$.ajax({
					type:'post',
					url:'delete',
					data:{
					    id : id
					},
					success:function (data) {
						if(data.code == 0){
						    window.location.reload();
						}else{
						    alert("删除失败");
						}
                    }
				});
            }

            function inquiry() {
				var batchId = $("#batchId").val();
			    var routeId = $("#routeId").val();

			    $.ajax({
					type:'post',
					url:'list',
					data:{
					    batchId : batchId,
						routeId : routeId
					},
					success:function(json){
                        //var vos = JSON.parse(json);//获取返回的所有VO类集合
                        var tbody = $("#tbody");
                        tbody.children('tr').remove();
                        $.each(json , function (n,vo) {
                            var data1 = '<tr><th><input type="checkbox" value="'+vo.transitBatchInfo.transitBatchId+'"/></th>'+
                                    '<th width="50">'+vo.transitBatchInfo.transitBatchId+'</th>'+
                                    '<th width="100">'+vo.transitBatchInfo.routeId+'</th>'+
                                    '<th width="100">'+vo.transportRouteInfor.routeName+'</th>'+
                                    '<th width="100">'+vo.transportRouteInfor.stationName+'</th>'+
                                    '<th width="150">'+vo.transitBatchInfo.startTime+'</th>'+
                                    '<th width="150">'+vo.transitBatchInfo.endTime+'</th>'+
                                    '<th width="100">'+vo.carInfo.licenseNumber+'</th>'+
                                    '<th width="100">'+vo.companyInfo.compname+'</th>'+
                                    '<th width="100"><input type="button" onclick="JavaScript:edit1('+vo.transitBatchInfo.transitBatchId+')"  value="编辑"/>'+
                                    '<input type="button" onclick="JavaScript:if(confirm(&apos;是否删除&apos;)){ delete1('+vo.transitBatchInfo.transitBatchId+')}" value="删除"/>'+
                                    '</th></tr>';
                            tbody.append(data1);
                        });
					}
				});
            }

		</script>
	</head>

	<body>
		<!--顶部导航 -->
		<nav class="topNavItemBox">
			<div id="ItemBox">
				<div class="title">肉品溯源管理系统</div>
			</div>
		</nav>
		<!-- 左侧导航 -->
		<#include "left.ftl"/>

        <!--物流信息查询 -->

		<div class="page_main">
			<h3>物流批次管理</h3><span class="add_link"><a href="/admin/transitBatchInfo/add">新增物流批次信息></a></span>
			<br />
			<div class="page_content">
				<h4>物流批次查询</h4>
				<br />
				<form  method="post" action="/admin/transitBatchInfo/list">
					<label>物流批次编号</label><input type="text" id="batchId" name="batchId" value="${batchId}" class="commonInputtext" /><span></span>
					<label>线路编号</label><input type="text" id="routeId" name="routeId" value="${routeId}" class="commonInputtext" />
					<input type="submit" value="查询"  style="display: inline-block; margin-left: 50px;" />
					<!--<span class="newQuarantine"> <a hrquarantineInfo_add.ftlhtml">新增检疫情况></a></span>-->
				</form>
				<div>
					<table id="transitBatch_table" class="table" width="100%">
						<thead>
							<tr>
								<th width="50"><input id="checkall" type="checkbox" /></th>
								<th width="70">批次编号</th>
								<th width="70">所属线路</th>
								<th width="100">所属线路名称</th>
								<th width="100">站点名称</th>
								<th width="150">开始时间</th>
								<th width="150">结束时间</th>
								<th width="100">货车车牌</th>
							    <th width="100">运输单位</th>
								<th width="100">操作</th>
								<!-- 可以修改公司    异步下拉  传ID值-->
							</tr>
						</thead>
						<tbody id="tbody">
							<#list page.list as infoVO>
								<tr>
									<th><input type="checkbox" value="${infoVO.transitBatchInfo.transitBatchId}"/></th>
									<th width="70">${infoVO.transitBatchInfo.transitBatchId}</th>
									<th width="70">${infoVO.transitBatchInfo.routeId}</th>
									<th width="100">${infoVO.transportRouteInfor.routeName}</th>
									<th width="100">${infoVO.transportRouteInfor.stationName}</th>
									<th width="150">${(infoVO.transitBatchInfo.startTime?string('yyyy-MM-dd hh:mm:ss'))}</th>
									<th width="150">${(infoVO.transitBatchInfo.endTime?string('yyyy-MM-dd hh:mm:ss'))}</th>
									<th width="100">${infoVO.carInfo.licenseNumber}</th>
									<th width="100">${infoVO.companyInfo.compname}</th>
									<th width="100"><input type="button"  value="编辑"/><input type="button" value="删除" onclick="JavaScript:if(confirm(&apos;是否删除&apos;)) { delete1(${infoVO.transitBatchInfo.transitBatchId})}"/></th>
								</tr>
							</#list>
						</tbody>
					</table>
				</div>
				<input type="button" id="deleteAllchoice" value="删除所选" style="display: none;" />
				<div id="barcon" name="barcon" style="margin-left: 200px;font-size:10px"></div>
			</div>


			<div class="footer">
				<div class="footer_lineone">
					<span id="logo"></span>肉品溯源管理系统 
					<span class="footer_lineoneSpan"><a href="aboutus.html">关于我们</a></span>
					<span class="footer_lineoneSpan"><a target="_blank" href="http://www.cfsiw.com/">食品安全信息</a></span> 
					<span class="footer_lineoneSpan"><a href="suggestionAdd.ftl">联系我们</a></span>
				</div>
				<div class="footer_linetwo">
					 &copy;2017广东技术师范学院
				</div>
			</div>
		</div>


		<script type="text/javascript" charset="UTF-8">
			$(function() {
				//初始化侧边栏
				$(".vertical-nav").verticalnav({
					speed: 400,
					align: "left"
				});
				
				
				var re_data; //每次传过来的数据
				//查询
				/*$("#transitBatchInfo_query").ajaxForm(function(data) {
					console.log(data);
					re_data = data;
					$("#transitBatch_table tbody tr").remove();
					for(var i = 0; i < data.length; i++) {
						var tb = $("#transitBatch_table tbody");
						var td_head = '<tr id="transitBatch_row' + data[i].transitBatchId + '">';
						var td1 = '<td><input type="checkbox" name="selectRows" class="isCheck" value="' + data[i].transitBatchId + '"/></td>';
						var td2 = '<td>' + data[i].transitBatchId + '</td>';
						var td3 = '<td>' + data[i].routeID + '</td>';
						var td4 = '<td>' + data[i].routeName + '</td>';
						var td5 = '<td>' + data[i].stationName + '</td>';
						var td6 = '<td>' + data[i].startTime.replace("T"," ") + '</td>';
						var td7 = '<td>' + data[i].endTime.replace("T"," ") + '</td>';
						var td8 = '<td>' + data[i].licenseNumber + '</td>';
						var td9 = '<td>' + data[i].carCompName + '</td>';
						var td10 = '<td><input type="button" onclick="updateData(' + i + ')" class="change" value="更改" style="padding:0 5px"/><input type="button" value="删除" onclick="deleteData(' + data[i].transitBatchId + ')" style="padding:0 5px" /></td>'
						var tr_add = td_head + td1 + td2 + td3 + td4 + td5 + td6 + td7 +td8+ td9 + td10 +'</tr>'
						tb.append(tr_add);
					}
					$("#no_data").remove();
					$("#deleteAllchoice").css("display", "block");
					goPage(1, 4, "transitBatch_table");
				});*/

				//多选
				$("#checkall").click(function() {
					$('input[class="isCheck"]').attr("checked", this.checked);
				});
				var $isCheck = $("input[class='isCheck']");
				$isCheck.click(function() {
					$("#checkall").attr("checked", $isCheck.length == $("input[class='isCheck']:checked").length ? true : false);
				});

				//删除

				function deleteByids(delete_data) {
					$.dialog({
						type: 'confirm',
						contentHtml: '<p style:"magrin:0 auto">确认删除？</p>',
						onClickOk: function() {
							$.ajax({
								url: "TransitBatchAction_deleteTransitBatch",
								data: {
									'selectRows': delete_data
								},
								success: function() {
									var chrstr = delete_data.split(",");
									for(i = 0; i < chrstr.length; i++) {
										$("#transitBatch_row" + chrstr[i]).remove();
									}
								}
							});
						}
					});

				}
				deleteData = function(i) {
					var st = i;
					st += ",";
					deleteByids(st);
				}
				$("#deleteAllchoice").click(function() {
					delete_data = get_checkbox_data();
					deleteByids(delete_data);
				});

				function get_checkbox_data() {
					var data_temp = "";
					$("input[class='isCheck']:checked").each(function() { // 遍历选中的checkbox
						data_temp += $(this).val() + ',';
						console.log(data_temp);
					});;
					return data_temp;

				}

				//更改

				updateData = function(i) {
					var row0 = '<form id="transitBatch_updateform" action="TransitBatchAction_updateTransitBatch" method="post">'
					var row1 = '<li><label class="labelBeforinput">物流批次编号</label><input name="transitBatchId" class="bigInputtext" readOnly="true" type="text" value="' + re_data[i].transitBatchId + '" /></li>';
					var row2 = '<li><label class="labelBeforinput">所属线路编号</label><input name="transportrouteInfor.routeId" class="bigInputtext" type="text" value="' + re_data[i].routeID + '"/></li>';
					var row3 = '<li><label class="labelBeforinput">开始运输时间</label><input name="startTime" class="bigInputtext" type="text" value="' + re_data[i].startTime.replace("T"," ") + '"/></li>';
					var row4 = '<li><label class="labelBeforinput">结束运输时间</label><input name="endTime" class="bigInputtext" type="text" value="' + re_data[i].endTime.replace("T"," ") + '" /></li>';
					var row5 = '<li><label class="labelBeforinput">运输货车(传ID)</label><input name="truckId" class="bigInputtext" type="text" value="' + re_data[i].carID + '" /></li>';
					var row6 = '<input type="hidden" name="routeID" value="' + re_data[i].routeID + '" />';
					var row7 = '<input type="hidden" name="carID" class="bigInputtext"  value="' + re_data[i].carID + '" />';
					var row8 = '<input type="hidden" name="routeName" value="' + re_data[i].routeName + '" />';
					var row9 = '<input type="hidden" name="stationName" value="' + re_data[i].stationName + '" />';
					var row11 = '<input type="hidden" name="carCompName" value="' + re_data[i].carCompName + '" />';/* 需要拿到异步里面的公司值 */
					var row12 = '<input type="hidden" name="routeRemark" value="' + re_data[i].routeRemark + '" />';
					var row13 = '<input type="hidden" name="carCompID" value="' + re_data[i].carCompID + '" />';
					var row14 = '<input type="hidden" name="stationNO" value="' + re_data[i].stationNO + '" />';
					var row15 = '<input type="hidden" name="licenseNumber" value="' + re_data[i].licenseNumber + '" />';/* 需要拿到异步里面的车牌号 */
					var rowLast = '</form>'
					var str = row0 + row1 + row2 + row3 + row4 + row5 + row6 + row7 + row8 + row9 +row11+row12+row13+row14+row15+rowLast;
					
					//console.log($("#transitBatch_table"));

					$.dialog({
						type: 'confirm',
						titleText: '更改数据',
						contentHtml: str,
						onClickOk: function() {
							$("#transitBatch_updateform").ajaxSubmit({
								type: 'post',
								error: function(XMLHttpRequest, textStatus, errorThrown) {
									//失败
									$.dialog({
										type: 'info',
										contentHtml: '<img class="info-icon" src="dialog/images/icon/fail.png" alt="更新失败" /><p class="info-text">更新失败</p>',
										autoClose: 2000
									});
								},
								success: function(data) {
									//成功弹窗
									$.dialog({
										type: 'info',
										contentHtml: '<img class="info-icon" src="dialog/images/icon/success.png" alt="更新成功" /><p class="info-text">更新成功</p>',
										autoClose: 2000
									});
									console.log(data);
									var row = $("#transitBatch_row" + data.transitbatchInfo.gid);
									console.log(row);
									row.find("td").eq(1).text(data.transitbatchInfo.transitBatchId);
									row.find("td").eq(2).text(data.transitbatchInfo.routeID);
									row.find("td").eq(3).text(data.transitbatchInfo.routeName);
									row.find("td").eq(4).text(data.transitbatchInfo.stationName);
									row.find("td").eq(5).text(data.transitbatchInfo.startTime);
									row.find("td").eq(6).text(data.transitbatchInfo.endTime);
									row.find("td").eq(7).text(data.transitbatchInfo.licenseNumber);
									row.find("td").eq(8).text(data.transitbatchInfo.carCompName);
									
									re_data[i] = data.transitbatchInfo;
								}

							});
						}

					});
				}

			});
		</script>

	</body>

</html>